﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MainFrame
{
    public partial class StartForm : Form
    {
        public StartForm()
        {
            InitializeComponent();
        }

        private void StartForm_Load(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterScreen;
        }

        private void btn_ResetCut_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && GlobalVar.isAutoRun)
            {
                var msg = "撕膜工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
            if (GlobalVar.Laser_pros == null || GlobalVar.Laser_pros.Count == 0)
            {
                GlobalVar.Laser_pros = new List<ProductInfo>();
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString()
                });
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString()
                });
            }
            GlobalMotion.e_ConveryLaser = e_Flow_ConveryUp.一段治具到位;
            this.Close();
        }

        private void btn_CutOver_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测2] && GlobalVar.isAutoRun)
            {
                var msg = "撕膜工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
            if (GlobalVar.Laser_pros == null || GlobalVar.Laser_pros.Count == 0)
            {
                GlobalVar.Laser_pros = new List<ProductInfo>();
                GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.一段治具升起);
                bool IshavePro1 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测1];
                bool IshavePro2 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测2];
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,
                    Result_up = IshavePro1 ? e_Result.进料OK.ToString() : e_Result.进料读卡NG.ToString(),
                    Result_Cut = IshavePro1 ? e_Result.撕膜OK.ToString() : e_Result.撕膜NG.ToString(),
                });
                GlobalVar.Laser_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = IshavePro2 ? e_Result.进料OK.ToString() : e_Result.进料读卡NG.ToString(),
                    Result_Cut = IshavePro2 ? e_Result.撕膜OK.ToString() : e_Result.撕膜NG.ToString(),
                });
            }
            GlobalMotion.e_ConveryLaser = e_Flow_ConveryUp.一段治具加工完成;
            this.Close();
        }

        private void btn_resetLabel_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && GlobalVar.isAutoRun)
            {
                var msg = "贴标工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
            if (GlobalVar.Label_pros == null || GlobalVar.Label_pros.Count == 0)
            {
                GlobalVar.Label_pros = new List<ProductInfo>();
               
                bool IshavePro3 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测3];
                bool IshavePro4 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测4];
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString(),

                });
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString()
                });
            }
            GlobalMotion.e_ConveryLabel = e_Flow_ConveryUp.二段治具到位;
            this.Close();
        }

        private void btn_LabelOver_Click(object sender, EventArgs e)
        {
            if (!GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送治具检测3] && GlobalVar.isAutoRun)
            {
                var msg = "贴标工位无治具,操作无效";
                MessageBox.Show(msg);
                return;
            }
            GlobalMotion.Step_ConveryUp(e_Step_ConveryUp.二段治具升起);
            if (GlobalVar.Label_pros == null || GlobalVar.Label_pros.Count == 0)
            {
                GlobalVar.Label_pros = new List<ProductInfo>();
                
                bool IshavePro3 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测3];
                bool IshavePro4 = !GlobalMotion.Input_CardEx2[(int)e_input_extCard2.上输送产品检测4];
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 1,
                    IsProcessAlarm = 1,

                    Result_up = e_Result.进料OK.ToString(),
                    Result_Label = IshavePro3 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                    Result_down = IshavePro3 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                });
                GlobalVar.Label_pros.Add(new ProductInfo()
                {
                    LaserTime = DateTime.Now,
                    typeName = GlobalVar.closeSave.CurrentTypeName,
                    ProId = "",
                    ProNo = 2,
                    IsProcessAlarm = 1,
                    Result_up = e_Result.进料OK.ToString(),
                    Result_Label = IshavePro4 ? e_Result.贴膜OK.ToString() : e_Result.贴膜NG.ToString(),
                    Result_down = IshavePro4 ? e_Result.出料OK.ToString() : e_Result.出料NG.ToString(),
                });
            }

            GlobalMotion.e_ConveryLabel = e_Flow_ConveryUp.二段治具加工完成;
            this.Close();
        }
    }
}
